package com.zzy.algorithm.sort;

/**
 * 插入排序
 */
public class Q27_InsertionSort {


    public static int[] nums = new int[]{5,7,1,2,8,9,3};

    public static void main(String[] args) {
        insertionSort(nums);
        for(int x : nums){
            System.out.println(x);
        }
    }



    private static void insertionSort(int[] nums){
        for(int i = 0; i < nums.length - 1;i++){
            int sortNum = nums[i + 1];
            int index = i;
            while(index >= 0 && sortNum < nums[index]){
                nums[index + 1] = nums[index];
                index--;
            }
            nums[index + 1] =  sortNum;
        }
    }

}
